<?php

namespace App\Admin\Controllers;

use SmallRuralDog\Admin\Controllers\AdminController;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use SmallRuralDog\Admin\Form;
use SmallRuralDog\Admin\Grid;
use SmallRuralDog\Admin\Auth\Database\Menu;
use SmallRuralDog\Admin\Components\Attrs\SelectOption;
use SmallRuralDog\Admin\Components\Form\IconChoose;
use SmallRuralDog\Admin\Components\Form\InputNumber;
use SmallRuralDog\Admin\Components\Form\Select;
use SmallRuralDog\Admin\Components\Form\Radio;
use SmallRuralDog\Admin\Components\Form\RadioGroup;
use SmallRuralDog\Admin\Components\Grid\Avatar;
use SmallRuralDog\Admin\Components\Grid\Icon;
use SmallRuralDog\Admin\Components\Grid\Tag;
use SmallRuralDog\Admin\Components\Grid\Image;
use SmallRuralDog\Admin\Grid\Actions\ActionButton;
use SmallRuralDog\Admin\Components\Widgets\Dialog;
use SmallRuralDog\Admin\Components\Widgets\BaseForm;
use SmallRuralDog\Admin\Components\Form\Input;
use SmallRuralDog\Admin\Components\Form\Upload;

use SmallRuralDog\Admin\Layout\Content;
use App\Models\Member;
use App\Models\MemberScoreLog;

class MemberScoreLogController extends AdminController
{

    protected function grid()
    {
        $grid = new Grid(new MemberScoreLog());
        $grid->defaultSort('id', 'desc');
        $grid->column('id', "日志ID")->width(100);
        $grid->column('member.name', "会员")->width(100); // 关联显示
        $grid->column('action', "动作")->customValue(function ($row, $value) {
            $action_name = ['increase'=>'增加','reduce'=>'减少'];
            return $action_name[$value];
        })->width(80);
        $grid->column('score', "积分")->sortable();
        $grid->column('remark', "说明")->showOverflowTooltip();
        $grid->column('created_at', "操作时间");
        $grid->actionLabel(''); // 隐藏操作

        $grid->actions(function (Grid\Actions $actions){
            $actions->hideActions(); // 隐藏操作
        })->toolbars(function (Grid\Toolbars $toolbars)
        {
            $toolbars->hideCreateButton();
        });

        // 自定义搜索
        $grid->quickSearch(function ($model, $query) {
            $member = Member::select('member_id')->where('name', $query)->orWhere('nickname', $query)->first();
            if ($member)
            {
                $query = $member->member_id;
            }
            $model->where('member_id', $query);
        });
        $grid->quickSearchPlaceholder("请输入客户姓名或昵称");

        return $grid;
    }

}
